package com.example.mybatisplusdemo.web.controller;

import com.example.mybatisplusdemo.common.JsonResponse;
import com.example.mybatisplusdemo.mapper.AirlineMapper;
import com.example.mybatisplusdemo.model.domain.Airline;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yrd
 * @since 2025-07-07
 */
@RestController
@RequestMapping("/api/flight")
@RequiredArgsConstructor
public class AirlineController {

    private final AirlineMapper airlineMapper;

    /**
     * 获取航空公司列表
     */
    @GetMapping("/airlines")
    public JsonResponse<Object> getAirlines() {
        try {
            List<Airline> airlines = airlineMapper.selectList(null);
            return JsonResponse.success(airlines, "航空公司列表获取成功");
        } catch (Exception e) {
            return JsonResponse.failure("获取航空公司列表失败: " + e.getMessage());
        }
    }
}
